package com.example.websocket.mapper;

import com.example.websocket.pojo.dto.UserListDto;
import com.example.websocket.pojo.po.RequestPo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * @ author 韩
 * time: 2024/3/11 18:59
 */
@Mapper
public interface FriendsMapper {

    @Select("select friend_name,note from friends where user_name = #{username} order by friend_name")
    List<UserListDto> selectFriendsByUserName(String username);

    @Select("select note from `friends` where user_name = #{username} AND friend_name = #{friendName}")
    String selectNote(String username,String friendName);

    @Update("update `friends` set note = #{note} where user_name = #{username} AND friend_name = #{friendName}")
    Boolean updateNote(String username, String friendName, String note);

    @Select("SELECT friend_name, note FROM friends WHERE user_name = #{username} AND friend_name LIKE CONCAT('%', #{key}, '%')")
    List<UserListDto> searchFriend(String username, String key);

    @Insert("insert into `friends`(user_name,friend_name) values (#{user_name},#{friend_name})")
    Boolean addFriend(String user_name, String friend_name);

    @Select("select * from `user` where username = #{username}")
    boolean selectPerson(String username);

    @Select("select * from `friends` where user_name = #{username} AND friend_name = #{friendName}")
    Boolean selectIsFriend(String username,String friendName);

    @Insert("insert into `friendrequest`(sender_username,receiver_username) values (#{mine},#{username})")
    boolean addFriendRequest(String mine, String username);

    @Select("select * from `friendrequest` where receiver_username = #{username} order by id desc")
    List<RequestPo> selectMyRequest(String username);

    @Update("update `friendrequest` set status = '已添加' where sender_username = #{sender_username} AND receiver_username = #{receiver_name}")
    Boolean agreeRequest(String sender_username, String receiver_name);

    @Delete("delete from `friends` where user_name = #{username} AND friend_name = #{deletedName}")
    Boolean deletedFriend(String deletedName, String username);
}
